import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import org.rsbot.event.events.MessageEvent;
import org.rsbot.event.listeners.MessageListener;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Bank;
import org.rsbot.script.methods.Calculations;
import org.rsbot.script.methods.Camera;
import org.rsbot.script.methods.Environment;
import org.rsbot.script.methods.Game;
import org.rsbot.script.methods.GrandExchange;
import org.rsbot.script.methods.Interfaces;
import org.rsbot.script.methods.Inventory;
import org.rsbot.script.methods.Keyboard;
import org.rsbot.script.methods.Menu;
import org.rsbot.script.methods.Mouse;
import org.rsbot.script.methods.NPCs;
import org.rsbot.script.methods.Objects;
import org.rsbot.script.methods.Players;
import org.rsbot.script.methods.Skills;
import org.rsbot.script.methods.Tiles;
import org.rsbot.script.methods.Walking;
import org.rsbot.script.util.Timer;
import org.rsbot.script.wrappers.RSComponent;
import org.rsbot.script.wrappers.RSInterface;
import org.rsbot.script.wrappers.RSItem;
import org.rsbot.script.wrappers.RSModel;
import org.rsbot.script.wrappers.RSNPC;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSPlayer;
import org.rsbot.script.wrappers.RSTile;

@ScriptManifest(authors={"Fallen"}, keywords={"Thieving"}, name="Fallen's Safe Cracker", version=4.3D, description="Cracks safes at Rogue Den's.")
public class FallenSafeCracker extends Script
  implements PaintListener, MessageListener, MouseListener, MouseMotionListener
{
  private long runTime;
  private long startTime;
  private long timeLeft;
  private long seconds;
  private long minutes;
  private long millis;
  private long hours;
  private int startXP;
  private int startLevel;
  private int levelsGained;
  private int currentLevel;
  private Image title;
  private int GainedProfit;
  private int XPGained;
  private int toNextLvl;
  private int nextLvl;
  private int XPToLevel;
  private double SuccessRate;
  private boolean setTime;
  private boolean paint;
  private boolean RT;
  private boolean extra;
  private boolean renew;
  private long timerStart;
  private long pauseTimer;
  private long tempTimer;
  private long tempTimer2;
  private boolean defined;
  private boolean gathered;
  private boolean switching;
  private boolean waitingForMovement;
  private Timer switchTimer;
  private int browseCounter;
  private final boolean logIfFull = true;
  private boolean UseStethoscope;
  private boolean randomized;
  private boolean North;
  private boolean South;
  private boolean SouthLeft;
  private boolean SouthRight;
  private boolean NorthLeft;
  private boolean NorthRight;
  private int getX;
  private int getY;
  private final int Percentage = 60;
  private Timer expTimeOut;
  private int tempExp;
  private int CrackState;
  private int Trapped;
  private int Cracked;
  private int FoodID;
  private final int[] FoodIDS;
  private static int FoodWDAmount;
  private static int EatingPoint;
  private final int Stethoscope = 5560;
  private final int Emerald = 1621;
  private final int Sapphire = 1623;
  private final int Ruby = 1619;
  private final int Diamond = 1617;
  private int Emeralds;
  private int Rubies;
  private int Sapphires;
  private int Diamonds;
  private int EmeraldsINV;
  private int RubiesINV;
  private int SapphiresINV;
  private int DiamondsINV;
  private final int wallsafe = 7236;
  private final int BankerID = 2271;
  private int EmeraldPrice;
  private int SapphirePrice;
  private int RubyPrice;
  private int DiamondPrice;
  private RSTile dest;
  private final RSTile approxBank;
  private Properties OPTION_FILE;
  private String GUIString;
  private Object GUIString2;
  private Object GUIString3;
  private Object GUIString4;
  private Object GUIString5;
  private Object GUIString6;
  private boolean TakeAShot;
  private boolean timeLimit;
  private boolean levelLimit;
  private boolean worked;
  private static int limitedHours;
  private static int limitedMinutes;
  private static int limitedLevel;
  private boolean change;
  private boolean advSwitch;
  private boolean clickFirst;
  private boolean up;
  public FallenSafeCracker.Spot NW;
  public FallenSafeCracker.Spot NE;
  public FallenSafeCracker.Spot SW;
  public FallenSafeCracker.Spot SE;
  public ArrayList<FallenSafeCracker.Spot> spots;
  public boolean WaitForStart;
  FallenSafeCracker.GUI SafeCrackerGUI;

  public FallenSafeCracker()
  {
    this.runTime = 0L;
    this.startTime = 0L;
    this.timeLeft = 0L;
    this.seconds = 0L;
    this.minutes = 0L;
    this.millis = 0L;
    this.hours = 0L;

    this.XPGained = 0;

    this.setTime = false;
    this.paint = true;
    this.RT = false;
    this.extra = true;
    this.renew = true;
    this.timerStart = 0L;
    this.pauseTimer = 0L;
    this.tempTimer = 0L;
    this.tempTimer2 = 0L;
    this.defined = false; this.gathered = false; this.switching = false; this.waitingForMovement = false;

    this.switchTimer = new Timer(0L);
    this.browseCounter = 0;
    this.logIfFull = true;

    this.randomized = false;
    this.North = false;
    this.South = false;
    this.SouthLeft = false;
    this.SouthRight = false;
    this.NorthLeft = false;
    this.NorthRight = false;

    this.Percentage = 60;

    this.expTimeOut = new Timer(300000L);
    this.tempExp = 0;

    this.CrackState = 0;
    this.Trapped = 0;
    this.Cracked = 0;

    this.FoodIDS = new int[] { 1895, 1893, 1891, 4293, 2142, 291, 2140, 3228, 9980, 7223, 6297, 6293, 6295, 6299, 7521, 9988, 7228, 2878, 7568, 2343, 1861, 13433, 315, 325, 319, 3144, 347, 355, 333, 339, 351, 329, 3381, 361, 10136, 5003, 379, 365, 373, 7946, 385, 397, 391, 3369, 3371, 3373, 2309, 2325, 2333, 2327, 2331, 2323, 2335, 7178, 7180, 7188, 7190, 7198, 7200, 7208, 7210, 7218, 7220, 2003, 2011, 2289, 2291, 2293, 2295, 2297, 2299, 2301, 2303, 1891, 1893, 1895, 1897, 1899, 1901, 7072, 7062, 7078, 7064, 7084, 7082, 7066, 7068, 1942, 6701, 6703, 7054, 6705, 7056, 7060, 2130, 1985, 1993, 1989, 1978, 5763, 5765, 1913, 5747, 1905, 5739, 1909, 5743, 1907, 1911, 5745, 2955, 5749, 5751, 5753, 5755, 5757, 5759, 5761, 2084, 2034, 2048, 2036, 2217, 2213, 2205, 2209, 2054, 2040, 2080, 2277, 2225, 2255, 2221, 2253, 2219, 2281, 2227, 2223, 2191, 2233, 2092, 2032, 2074, 2030, 2281, 2235, 2064, 2028, 2187, 2185, 2229, 6883, 1971, 4608, 1883, 1885, 15272 };

    this.Stethoscope = 5560;
    this.Emerald = 1621;
    this.Sapphire = 1623;
    this.Ruby = 1619;
    this.Diamond = 1617;

    this.wallsafe = 7236;
    this.BankerID = 2271;

    this.EmeraldPrice = 0;
    this.SapphirePrice = 0;
    this.RubyPrice = 0;
    this.DiamondPrice = 0;

    this.dest = new RSTile(3056, 4978);
    this.approxBank = new RSTile(3042, 4970);

    this.TakeAShot = false;
    this.timeLimit = false;
    this.levelLimit = false;
    this.worked = false;

    this.change = true; this.advSwitch = true; this.clickFirst = false; this.up = false;

    this.NW = new FallenSafeCracker.Spot(this, new RSTile(3055, 4970)); this.NE = new FallenSafeCracker.Spot(this, new RSTile(3057, 4970)); this.SW = new FallenSafeCracker.Spot(this, new RSTile(3055, 4977)); this.SE = new FallenSafeCracker.Spot(this, new RSTile(3057, 4977));

    this.spots = new ArrayList();

    this.WaitForStart = true;
  }

  public void onRepaint(Graphics paramGraphics)
  {
    if ((!this.game.isLoggedIn()) || (isPaused()) || (!isActive())) {
      if (!this.gathered) {
        this.timerStart = System.currentTimeMillis();
        this.gathered = true;
      }
      this.tempTimer = (System.currentTimeMillis() - this.timerStart - this.tempTimer2);
    } else {
      this.tempTimer = 0L;
      this.tempTimer2 = 0L;
      this.gathered = false;
    }
    this.pauseTimer += this.tempTimer;
    this.tempTimer2 += this.tempTimer;
    if (this.startXP == 0) {
      this.startXP = this.skills.getCurrentExp(17);
    }
    if (this.startLevel == 0) {
      this.startLevel = this.skills.getRealLevel(17);
    }
    if (this.RT == true)
      this.runTime = (System.currentTimeMillis() - this.startTime);
    else {
      this.runTime = (System.currentTimeMillis() - this.startTime - this.pauseTimer);
    }
    this.XPGained = (this.skills.getCurrentExp(17) - this.startXP);
    this.GainedProfit = (this.Emeralds * this.EmeraldPrice + this.Rubies * this.RubyPrice + this.Sapphires * this.SapphirePrice + this.Diamonds * this.DiamondPrice);

    int i = (int)(this.XPGained * 3600000.0D / this.runTime);
    int j = (int)(this.GainedProfit * 3600000.0D / this.runTime);
    int k = this.Cracked + this.Trapped;
    this.levelsGained = (this.skills.getRealLevel(17) - this.startLevel);
    this.currentLevel = this.skills.getRealLevel(17);
    this.millis = this.runTime;
    this.hours = (this.millis / 3600000L);
    this.millis -= this.hours * 3600000L;
    this.minutes = (this.millis / 60000L);
    this.millis -= this.minutes * 60000L;
    this.seconds = (this.millis / 1000L);
    Point localPoint = this.mouse.getLocation();
    paramGraphics.setColor(new Color(170, 10, 170, 180));
    paramGraphics.fillRoundRect((int)localPoint.getX() - 10, (int)localPoint.getY() - 1, 21, 3, 3, 3);

    paramGraphics.fillRoundRect((int)localPoint.getX() - 1, (int)localPoint.getY() - 10, 3, 21, 3, 3);
    long l1;
    long l2;
    long l3;
    if (this.waitingForMovement) {
      l1 = this.switchTimer.getRemaining() / 1000L;
      l2 = l1 / 3600L;
      l1 -= l2 * 3600L;
      l3 = l1 / 60L;
      l1 -= l3 * 60L;
      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.setColor(Color.RED);
      paramGraphics.drawString("A player is under us, waiting - " + l3 + " minutes, " + l1 + " seconds.", 140, 470);
    }

    if (this.switching) {
      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.setColor(Color.RED);
      paramGraphics.drawString("Switching location.", 220, 470);
    }

    paramGraphics.setFont(new Font("Verdana", 0, 10));

    if (this.paint)
      paramGraphics.setColor(new Color(20, 255, 20, 130));
    else {
      paramGraphics.setColor(new Color(255, 255, 255, 130));
    }
    paramGraphics.fillRect(416, 458, 32, 15);
    paramGraphics.setColor(new Color(0, 0, 0, 255));
    paramGraphics.drawRect(416, 458, 32, 15);
    paramGraphics.setColor(new Color(0, 0, 0, 255));
    paramGraphics.drawString("Paint", 418, 470);

    paramGraphics.setFont(new Font("Verdana", 0, 10));
    if (this.RT == true)
      paramGraphics.setColor(new Color(156, 20, 170, 130));
    else {
      paramGraphics.setColor(new Color(255, 255, 255, 130));
    }
    paramGraphics.fillRect(448, 458, 32, 15);
    paramGraphics.setColor(new Color(0, 0, 0, 255));
    paramGraphics.drawRect(448, 458, 32, 15);
    paramGraphics.setColor(new Color(0, 0, 0, 255));
    paramGraphics.drawString("Time", 450, 470);

    paramGraphics.setFont(new Font("Verdana", 0, 10));
    if (this.extra == true)
      paramGraphics.setColor(new Color(255, 90, 60, 130));
    else {
      paramGraphics.setColor(new Color(255, 255, 255, 130));
    }
    paramGraphics.fillRect(480, 458, 32, 15);
    paramGraphics.setColor(new Color(0, 0, 0, 255));
    paramGraphics.drawRect(480, 458, 32, 15);
    paramGraphics.setColor(new Color(0, 0, 0, 255));
    paramGraphics.drawString("Extra", 482, 470);

    if (this.paint) {
      paramGraphics.drawImage(this.title, 9, 30, null);

      paramGraphics.setFont(new Font("Arial", 0, 10));
      paramGraphics.setColor(Color.MAGENTA);
      paramGraphics.drawString("v 4.3", 171, 80);

      paramGraphics.setFont(new Font("Verdana", 0, 15));
      paramGraphics.setColor(Color.WHITE);
      if (this.setTime == true) {
        paramGraphics.drawString(" " + this.hours + ":" + this.minutes + ":" + this.seconds + ".", 47, 315);
      }
      else {
        paramGraphics.drawString("Loading...", 47, 315);
      }
      if ((this.timeLimit == true) && (this.setTime == true)) {
        paramGraphics.setFont(new Font("Verdana", 0, 9));
        paramGraphics.setColor(Color.RED);
        l1 = this.timeLeft - this.runTime / 1000L;
        l2 = l1 / 3600L;
        l1 -= l2 * 3600L;
        l3 = l1 / 60L;
        l1 -= l3 * 60L;
        paramGraphics.drawString("Time left: " + l2 + " hours, " + l3 + " minutes.", 355, 14);
      }

      paramGraphics.setFont(new Font("Verdana", 0, 12));
      paramGraphics.setColor(Color.MAGENTA);
      paramGraphics.drawString("Exp/Hour: " + i, 60, 115);

      paramGraphics.setColor(Color.MAGENTA);
      paramGraphics.drawString("Profit/Hour: " + j, 60, 212);

      paramGraphics.setColor(Color.WHITE);
      paramGraphics.setFont(new Font("Verdana", 0, 11));

      paramGraphics.setFont(new Font("Verdana", 0, 9));
      this.toNextLvl = this.skills.getPercentToNextLevel(17);
      this.XPToLevel = this.skills.getExpToNextLevel(17);
      this.nextLvl = (this.skills.getCurrentLevel(17) + 1);
      paramGraphics.setColor(new Color(0, 0, 0));
      paramGraphics.fillRect(19, 125, 180, 16);
      paramGraphics.drawRect(18, 124, 181, 17);
      paramGraphics.setColor(new Color(51, 51, 51));
      paramGraphics.fillRect(19, 125, 180, 8);
      paramGraphics.setColor(new Color(170, 10, 170, 130));
      paramGraphics.fillRect(20, 126, (int)(this.toNextLvl * 178 / 100.0D), 14);
      paramGraphics.setColor(Color.WHITE);
      paramGraphics.drawString("" + this.toNextLvl + "% to " + this.nextLvl + " Thiev" + " - " + this.XPToLevel + " XP", 25, 137);
      try
      {
        if (i > 0) {
          l1 = this.XPToLevel / (i / 3600);
          l2 = l1 / 3600L;
          l1 -= l2 * 3600L;
          l3 = l1 / 60L;
          l1 -= l3 * 60L;
          paramGraphics.drawString("Next level in: " + l2 + ":" + l3 + ":" + l1, 19, 154);
        }
        else {
          paramGraphics.drawString("Next level in: 0:0:0", 19, 154);
        }
      } catch (Exception localException) {
        paramGraphics.drawString("Next level in: -1:-1:-1", 19, 154);
      }

      paramGraphics.drawString("Thieving EXP gained: " + this.XPGained, 19, 174);
      paramGraphics.drawString("Thieving level: " + this.currentLevel + " (" + this.levelsGained + ")", 19, 186);

      if (this.levelLimit == true) {
        paramGraphics.setFont(new Font("Verdana", 0, 9));
        paramGraphics.setColor(Color.RED);
        paramGraphics.drawString("Stopping at level " + limitedLevel + " Thieving.", 363, 14);
      }

      paramGraphics.drawString("Total profit: " + this.GainedProfit, 19, 234);
      paramGraphics.setColor(Color.BLUE);
      paramGraphics.drawString("Sapphires: " + this.Sapphires, 19, 246);
      paramGraphics.setColor(Color.GREEN);
      paramGraphics.drawString("Emeralds: " + this.Emeralds, 19, 258);
      paramGraphics.setColor(Color.RED);
      paramGraphics.drawString("Rubies: " + this.Rubies, 19, 270);
      paramGraphics.setColor(Color.WHITE);
      paramGraphics.drawString("Diamonds: " + this.Diamonds, 19, 282);
    }
    if (this.extra)
    {
      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.setColor(Color.WHITE);
      paramGraphics.drawString("Cracked: " + this.Cracked, 340, 310);

      paramGraphics.drawString("Failed: " + this.Trapped, 340, 298);

      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.setColor(new Color(0, 0, 0));
      paramGraphics.fillRect(341, 316, 169, 16);
      paramGraphics.drawRect(340, 315, 170, 17);
      paramGraphics.setColor(new Color(51, 51, 51));
      paramGraphics.fillRect(341, 316, 169, 8);
      paramGraphics.setColor(new Color(200, 0, 0, 60));
      paramGraphics.fillRect(343, 318, 165, 12);
      paramGraphics.setColor(new Color(30, 255, 30, 80));
      if (this.SuccessRate != 0.0D) {
        paramGraphics.fillRect(343, 318, (int)(this.SuccessRate * 165.0D / 100.0D), 12);
      }
      paramGraphics.setColor(Color.WHITE);
      paramGraphics.drawString("" + Math.round(this.SuccessRate) + " % Success", 390, 328);
      paramGraphics.setColor(Color.WHITE);
      if (this.Cracked > 0) {
        this.SuccessRate = (this.Cracked * 100.0D / k);
      }

      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.setColor(new Color(51, 51, 0));
      paramGraphics.fillRoundRect(448, 257, 43, 26, 8, 8);
      if (this.South) {
        paramGraphics.setColor(Color.GREEN);
        paramGraphics.drawString("South", 455, 307);
        paramGraphics.drawRoundRect(450, 270, 38, 27, 10, 10);
      } else {
        paramGraphics.setColor(Color.RED);
        paramGraphics.drawString("South", 455, 307);
        paramGraphics.drawRoundRect(450, 270, 38, 27, 10, 10);
      }
      if (this.North) {
        paramGraphics.setColor(Color.GREEN);
        paramGraphics.drawString("North", 455, 237);
        paramGraphics.drawRoundRect(450, 240, 38, 27, 10, 10);
      } else {
        paramGraphics.setColor(Color.RED);
        paramGraphics.drawString("North", 455, 237);
        paramGraphics.drawRoundRect(450, 240, 38, 27, 10, 10);
      }

      paramGraphics.setFont(new Font("Verdana", 0, 12));

      if (this.NorthLeft) {
        paramGraphics.setColor(Color.GREEN);
        paramGraphics.drawString("W", 432, 275);
        paramGraphics.drawString("*", 459, 262);
      } else {
        paramGraphics.setColor(Color.RED);
        paramGraphics.drawString("W", 432, 275);
        paramGraphics.drawString("*", 459, 262);
      }
      if (this.NorthRight) {
        paramGraphics.setColor(Color.GREEN);
        paramGraphics.drawString("E", 494, 275);
        paramGraphics.drawString("*", 475, 262);
      } else {
        paramGraphics.setColor(Color.RED);
        paramGraphics.drawString("E", 494, 275);
        paramGraphics.drawString("*", 475, 262);
      }
      if (this.SouthLeft) {
        paramGraphics.setColor(Color.GREEN);
        paramGraphics.drawString("W", 432, 275);
        paramGraphics.drawString("*", 459, 290);
      } else {
        paramGraphics.setColor(Color.RED);
        paramGraphics.drawString("W", 432, 275);
        paramGraphics.drawString("*", 459, 290);
      }
      if (this.SouthRight) {
        paramGraphics.setColor(Color.GREEN);
        paramGraphics.drawString("E", 494, 275);
        paramGraphics.drawString("*", 475, 290);
      } else {
        paramGraphics.setColor(Color.RED);
        paramGraphics.drawString("E", 494, 275);
        paramGraphics.drawString("*", 475, 290);
      }
    }
  }

  public void drawTile(Graphics paramGraphics, RSTile paramRSTile, Color paramColor, boolean paramBoolean, String paramString)
  {
    Point localPoint1 = this.calc.tileToScreen(paramRSTile, 0.0D, 0.0D, 0);
    Point localPoint2 = this.calc.tileToScreen(new RSTile(paramRSTile.getX() + 1, paramRSTile.getY()), 0.0D, 0.0D, 0);

    Point localPoint3 = this.calc.tileToScreen(new RSTile(paramRSTile.getX(), paramRSTile.getY() + 1), 0.0D, 0.0D, 0);

    Point localPoint4 = this.calc.tileToScreen(new RSTile(paramRSTile.getX() + 1, paramRSTile.getY() + 1), 0.0D, 0.0D, 0);

    if ((this.calc.pointOnScreen(localPoint1)) && (this.calc.pointOnScreen(localPoint2)) && (this.calc.pointOnScreen(localPoint3)) && (this.calc.pointOnScreen(localPoint4)))
    {
      paramGraphics.setColor(Color.BLACK);
      paramGraphics.drawPolygon(new int[] { (int)localPoint3.getX(), (int)localPoint4.getX(), (int)localPoint2.getX(), (int)localPoint1.getX() }, new int[] { (int)localPoint3.getY(), (int)localPoint4.getY(), (int)localPoint2.getY(), (int)localPoint1.getY() }, 4);

      paramGraphics.setColor(paramColor);
      paramGraphics.fillPolygon(new int[] { (int)localPoint3.getX(), (int)localPoint4.getX(), (int)localPoint2.getX(), (int)localPoint1.getX() }, new int[] { (int)localPoint3.getY(), (int)localPoint4.getY(), (int)localPoint2.getY(), (int)localPoint1.getY() }, 4);

      if (paramBoolean) {
        paramGraphics.setColor(Color.WHITE);
        paramGraphics.drawString("" + paramString, localPoint1.x, localPoint1.y);
      }
    }
  }

  public boolean onStart()
  {
    try
    {
      this.title = ImageIO.read(new URL("http://a.imageshack.us/img641/4190/paintv20.png"));
    }
    catch (IOException localIOException) {
      localIOException.printStackTrace();
    }
    this.OPTION_FILE = new Properties();
    this.SafeCrackerGUI = new FallenSafeCracker.GUI(this, this);
    this.SafeCrackerGUI.setLocationRelativeTo(null);
    this.SafeCrackerGUI.setVisible(true);

    while (this.WaitForStart) {
      sleep(20);
    }
    if (!this.worked)
      return false;
    this.spots.add(this.NW);
    this.spots.add(this.NE);
    this.spots.add(this.SW);
    this.spots.add(this.SE);
    log("Retrieving item prices from the Grand Exchange...");

    this.SapphirePrice = getGuidePrice(1623);
    this.EmeraldPrice = getGuidePrice(1621);
    this.RubyPrice = getGuidePrice(1619);
    this.DiamondPrice = getGuidePrice(1617);
    this.EmeraldsINV = this.inventory.getCount(new int[] { 1621 });
    this.RubiesINV = this.inventory.getCount(new int[] { 1619 });
    this.SapphiresINV = this.inventory.getCount(new int[] { 1623 });
    this.DiamondsINV = this.inventory.getCount(new int[] { 1617 });
    log("... Prices retrieved!");
    log(" ~ Anti-ban synchronized! ~");
    log("------------------------------------------------");
    log("Fallen's Safe Cracker is now running!");
    this.startTime = System.currentTimeMillis();
    this.timeLeft = ((limitedHours * 60 * 60 * 1000 + limitedMinutes * 60 * 1000) / 1000);
    this.setTime = true;
    this.camera.setPitch(true);
    return true;
  }

  private int getGuidePrice(int paramInt)
  {
    try
    {
      URL localURL = new URL("http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=" + paramInt);

      BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(localURL.openStream()));

      String str = null;

      while ((str = localBufferedReader.readLine()) != null)
        if (str.contains("<b>Current guide price:</b>")) {
          str = str.replace("<b>Current guide price:</b>", "");
          return (int)parse(str);
        }
    }
    catch (IOException localIOException) {
    }
    return -1;
  }

  private double parse(String paramString) {
    if ((paramString != null) && (!paramString.isEmpty())) {
      paramString = stripFormatting(paramString);
      paramString = paramString.substring(paramString.indexOf(':') + 2, paramString.length());
      paramString = paramString.replace(",", "");
      if (!paramString.endsWith("%")) {
        if ((!paramString.endsWith("k")) && (!paramString.endsWith("m"))) {
          return Double.parseDouble(paramString);
        }
        return Double.parseDouble(paramString.substring(0, paramString.length() - 1)) * (paramString.endsWith("m") ? 1000000 : 1000);
      }

      int i = paramString.startsWith("+") ? 1 : -1;
      paramString = paramString.substring(1);
      return Double.parseDouble(paramString.substring(0, paramString.length() - 1)) * i;
    }
    return -1.0D;
  }

  private String stripFormatting(String paramString) {
    if ((paramString != null) && (!paramString.isEmpty()))
      return paramString.replaceAll("(^[^<]+>|<[^>]+>|<[^>]+$)", "");
    return "";
  }

  private boolean failSafes() {
    if (!gainedExperience()) {
      Quit();
      return true;
    }
    return false;
  }

  private boolean gainedExperience() {
    if (!this.expTimeOut.isRunning()) {
      if (this.XPGained > this.tempExp) {
        this.expTimeOut = new Timer(300000L);
        this.tempExp = this.XPGained;
        return true;
      }
      log("No experience gained withtin the past 5 minutes!");
      return false;
    }

    return true;
  }

  private void timeToQuit() {
    if (this.timeLimit == true) {
      if ((limitedHours == this.hours) && (limitedMinutes <= this.minutes)) {
        log("Time's up!");
        Quit();
      } else if (limitedHours < this.hours) {
        log("Time's up!");
        Quit();
      }
    }
    if ((this.levelLimit == true) && 
      (this.currentLevel == limitedLevel)) {
      log("Achieved level: " + this.currentLevel);
      Quit();
    }
  }

  private boolean waitForIF(RSInterface paramRSInterface, int paramInt)
  {
    long l = System.currentTimeMillis();

    while (System.currentTimeMillis() - l < paramInt) {
      if (paramRSInterface.isValid()) {
        return true;
      }
      sleep(100);
    }
    return false;
  }

  private boolean inRectangle(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
    this.getX = getMyPlayer().getLocation().getX();
    this.getY = getMyPlayer().getLocation().getY();

    return (this.getX >= paramInt1) && (this.getX <= paramInt3) && (this.getY >= paramInt2) && (this.getY <= paramInt4);
  }

  private boolean waitForWithdrawnItem(int paramInt1, int paramInt2)
  {
    int i = this.inventory.getCount(true, new int[] { paramInt1 });
    long l = System.currentTimeMillis();

    while (System.currentTimeMillis() - l < paramInt2) {
      if (this.inventory.getCount(new int[] { paramInt1 }) > i) {
        return true;
      }
      sleep(100);
    }
    return false;
  }

  private boolean waitForDepositedItem(int paramInt) {
    int i = this.inventory.getCount(true);
    long l = System.currentTimeMillis();

    while (System.currentTimeMillis() - l < paramInt) {
      if (this.inventory.getCount(true) < i) {
        return true;
      }
      sleep(100);
    }
    return false;
  }

  private boolean waitForStateChange(int paramInt) {
    long l = System.currentTimeMillis();

    while (System.currentTimeMillis() - l < paramInt) {
      if ((this.CrackState != 1) || (safeToCrack(getMyPlayer().getLocation()) == null))
      {
        if ((this.clickFirst) && (!this.inventory.isItemSelected())) {
          useStethoscope();
        }
        return true;
      }
      sleep(100);
      if (random(0, 100) > 70) {
        antiBan();
      }
      if ((random(0, 20) != random(0, 20)) || (!this.clickFirst) || (this.inventory.isItemSelected()))
        continue;
      useStethoscope();
    }

    return false;
  }

  private boolean waitToStop(int paramInt) {
    long l = System.currentTimeMillis();
    while (System.currentTimeMillis() - l < paramInt) {
      if (!getMyPlayer().isMoving()) {
        return true;
      }
      sleep(50);
    }
    return false;
  }

  private boolean waitForAnim(int paramInt) {
    long l = System.currentTimeMillis();
    while (System.currentTimeMillis() - l < paramInt) {
      if (getMyPlayer().getAnimation() != -1) {
        return true;
      }
      sleep(50);
    }
    return false;
  }

  private boolean WD(int paramInt1, int paramInt2) {
    int i = paramInt2;
    if (paramInt2 == 0)
      i = 1;
    if (paramInt2 < 0)
      throw new IllegalArgumentException("count < 0 (" + paramInt2 + ")");
    if (!this.bank.isOpen())
      return false;
    RSItem localRSItem = this.bank.getItem(paramInt1);
    if ((localRSItem != null) && (localRSItem.isComponentValid())) { if (this.bank.getCount(new int[] { paramInt1 }) >= i); } else {
      if (this.bank.getCount(new int[] { paramInt1 }) < i) {
        log("Out of items - Check: 1/3.");
        sleep(random(400, 600));
        if (this.bank.getCount(new int[] { paramInt1 }) < i) {
          log("Out of items - Check: 2/3.");
          sleep(random(400, 600));
          if ((this.bank.getCount(new int[] { paramInt1 }) < i) && (this.bank.isOpen())) {
            try {
              log("Out of: " + this.grandExchange.getItemName(paramInt1) + " - Check 3/3.");
            }
            catch (Exception localException) {
              localException.printStackTrace();
              log("Out of: " + paramInt1);
            }
            Quit();
            return false;
          }
        }
      }
      return false;
    }
    switch (paramInt2) {
    case 0:
      return localRSItem.doAction("Withdraw-All");
    case 1:
      return localRSItem.doClick(true);
    case 5:
    case 10:
      return localRSItem.doAction("Withdraw-" + paramInt2);
    }
    if (localRSItem.doClick(false)) {
      sleep(random(100, 300));
      if (this.menu.contains("Withdraw-" + paramInt2)) {
        if (this.menu.doAction("Withdraw-" + paramInt2)) {
          sleep(random(100, 200));
          return true;
        }
        return false;
      }
      if (localRSItem.doAction("Withdraw-X")) {
        sleep(random(1000, 1300));
        this.keyboard.sendText("" + paramInt2, true);
      }
      sleep(random(100, 200));
      return true;
    }

    return false;
  }

  private boolean doActionAtModel(RSModel paramRSModel, String paramString) {
    if (paramRSModel != null) {
      int i = random(3, 6);
      while (true) { i--; if ((i <= 0) || (this.menu.contains(paramString))) break;
        try {
          this.mouse.move(paramRSModel.getPoint());
          if (this.menu.contains(paramString)) {
            sleep(random(20, 100));
            if (this.menu.contains(paramString))
              break;
          }
        }
        catch (Exception localException)
        {
        } }
      if (this.menu.contains(paramString)) {
        return this.menu.doAction(paramString);
      }
      return false;
    }

    return false;
  }

  private RSObject safeToCrack(RSTile paramRSTile) {
    RSObject[] arrayOfRSObject1 = this.objects.getAllAt(paramRSTile);
    for (RSObject localRSObject : arrayOfRSObject1) {
      if (localRSObject.getID() == 7236) {
        return localRSObject;
      }
    }
    return null;
  }

  private boolean waitForSafe(int paramInt) {
    long l = System.currentTimeMillis();
    while (System.currentTimeMillis() - l < paramInt) {
      if (safeToCrack(getMyPlayer().getLocation()) != null) {
        return true;
      }
      sleep(50);
    }
    return false;
  }

  private boolean useStethoscope() {
    RSItem localRSItem = this.inventory.getItem(new int[] { 5560 });
    if (localRSItem != null) {
      return localRSItem.doClick(true);
    }
    return false;
  }

  private void crackSafe() {
    RSTile localRSTile = getMyPlayer().getLocation();
    if (eat()) {
      return;
    }
    String str = "Crack";
    if (this.clickFirst) {
      str = "Use Stethoscope -> Wall safe";
      if (!this.inventory.isItemSelected()) {
        useStethoscope();
      }
    }
    RSObject localRSObject = safeToCrack(localRSTile);
    RSModel localRSModel;
    if (localRSObject != null)
      localRSModel = localRSObject.getModel();
    else {
      return;
    }
    long l = System.currentTimeMillis();
    int i = 0;
    while ((i == 0) && (System.currentTimeMillis() - l < 5000L)) {
      if (doActionAtModel(localRSModel, str)) {
        i = 1;
        if (random(0, 100) > 70) {
          this.mouse.moveRandomly(200);
        }
        this.CrackState = 1;
        return;
      }
      i = 0;
      sleep(random(200, 600));
    }
    this.CrackState = 1;
  }

  private void scanner()
  {
    if (inRectangle(3052, 4974, 3060, 4981)) {
      this.North = true;
      this.South = false;
    } else if (inRectangle(3052, 4966, 3060, 4973)) {
      this.North = false;
      this.South = true;
    } else {
      this.North = false;
      this.South = false;
    }

    if (inRectangle(3055, 4970, 3055, 4970)) {
      this.SouthLeft = true;
      this.SouthRight = false;
      this.NorthLeft = false;
      this.NorthRight = false;
    } else if (inRectangle(3057, 4970, 3057, 4970)) {
      this.SouthLeft = false;
      this.SouthRight = true;
      this.NorthLeft = false;
      this.NorthRight = false;
    } else if (inRectangle(3055, 4977, 3055, 4977)) {
      this.SouthLeft = false;
      this.SouthRight = false;
      this.NorthLeft = true;
      this.NorthRight = false;
    } else if (inRectangle(3057, 4977, 3057, 4977)) {
      this.SouthLeft = false;
      this.SouthRight = false;
      this.NorthLeft = false;
      this.NorthRight = true;
    } else {
      this.SouthLeft = false;
      this.SouthRight = false;
      this.NorthLeft = false;
      this.NorthRight = false;
    }

    for (int i = 0; i < 4; i++) {
      ((FallenSafeCracker.Spot)this.spots.get(i)).setFree(true);
    }
    RSPlayer[] arrayOfRSPlayer1 = this.players.getAll();
    for (RSPlayer localRSPlayer : arrayOfRSPlayer1)
      if (localRSPlayer != null) {
        RSTile localRSTile = localRSPlayer.getLocation();
        for (int m = 0; m < 4; m++)
          if (localRSTile.equals(((FallenSafeCracker.Spot)this.spots.get(m)).location))
            ((FallenSafeCracker.Spot)this.spots.get(m)).setFree(false);
      }
  }

  private boolean someoneBeneathMe()
  {
    RSTile localRSTile = getMyPlayer().getLocation();
    RSPlayer[] arrayOfRSPlayer1 = this.players.getAll();

    for (RSPlayer localRSPlayer : arrayOfRSPlayer1) {
      try {
        if ((!localRSPlayer.equals(getMyPlayer())) && 
          (localRSPlayer.getLocation().equals(localRSTile)))
          return true;
      }
      catch (Exception localException)
      {
      }
    }
    return false;
  }

  private RSTile nearestFreeSpot(boolean paramBoolean) {
    ArrayList localArrayList = new ArrayList();
    int i = 20;
    RSTile localRSTile = null;
    for (int j = 0; j < 4; j++) {
      if (((FallenSafeCracker.Spot)this.spots.get(j)).free) {
        localArrayList.add(((FallenSafeCracker.Spot)this.spots.get(j)).location);
        int k = this.calc.distanceTo(((FallenSafeCracker.Spot)this.spots.get(j)).location);
        if (k < i) {
          localRSTile = ((FallenSafeCracker.Spot)this.spots.get(j)).location;
          i = k;
        }
      }
    }
    if ((paramBoolean) && (random(0, 2) == random(0, 2))) {
      return (RSTile)localArrayList.get(random(0, localArrayList.size()));
    }
    return localRSTile;
  }

  private boolean waitToGetClose(int paramInt1, int paramInt2)
  {
    long l = System.currentTimeMillis();
    if (!waitToMove(random(800, 1400))) {
      return false;
    }
    while (System.currentTimeMillis() - l < paramInt2) {
      if (paramInt1 >= 0) {
        if (this.walking.getDestination() != null)
        {
          try
          {
            if (this.calc.distanceTo(this.walking.getDestination()) <= paramInt1)
              return true;
          }
          catch (Exception localException1) {
            this.log.severe("Failed to get destination.");
          }
        }
        else return true;

      }
      else if (this.walking.getDestination() != null)
      {
        try
        {
          if (this.calc.tileOnScreen(this.walking.getDestination()))
            return true;
        }
        catch (Exception localException2) {
          this.log.severe("Failed to get destination.");
        }
      }
      else return true;

      sleep(100);
    }
    return false;
  }

  private boolean waitToMove(int paramInt) {
    long l = System.currentTimeMillis();
    while (System.currentTimeMillis() - l < paramInt) {
      if (getMyPlayer().isMoving()) {
        return true;
      }
      sleep(50);
    }
    return false;
  }

  private void CameraAntiBan() {
    int i = random(1, 2);
    int j = random(1, 1000);
    if (j >= 930)
      switch (i) {
      case 1:
        new FallenSafeCracker.CameraRotateThread(this).start();
        break;
      case 2:
        int k = random(0, 2);
        if (k == 0) {
          new FallenSafeCracker.CameraRotateThread(this).start();
        } else {
          new FallenSafeCracker.CameraRotateThread(this).start();
          new FallenSafeCracker.CameraRotateThread(this).start();
        }
      }
  }

  private void getInvCounts()
  {
    if (this.inventory.getCount(new int[] { 1621 }) > this.EmeraldsINV) {
      this.Emeralds += 1;
    }
    if (this.inventory.getCount(new int[] { 1623 }) > this.SapphiresINV) {
      this.Sapphires += 1;
    }
    if (this.inventory.getCount(new int[] { 1619 }) > this.RubiesINV) {
      this.Rubies += 1;
    }
    if (this.inventory.getCount(new int[] { 1617 }) > this.DiamondsINV) {
      this.Diamonds += 1;
    }
    this.EmeraldsINV = this.inventory.getCount(new int[] { 1621 });
    this.RubiesINV = this.inventory.getCount(new int[] { 1619 });
    this.SapphiresINV = this.inventory.getCount(new int[] { 1623 });
    this.DiamondsINV = this.inventory.getCount(new int[] { 1617 });
  }

  private boolean eat() {
    if ((this.inventory.containsOneOf(this.FoodIDS)) && (Integer.parseInt(this.interfaces.get(748).getComponent(8).getText()) <= EatingPoint))
    {
      RSItem localRSItem1 = this.inventory.getItem(this.FoodIDS);
      if ((localRSItem1 != null) && 
        (localRSItem1.doAction("eat"))) {
        waitForAnim(1000);
        sleep(random(200, 400));
      }

      if ((this.inventory.containsOneOf(this.FoodIDS)) && (Integer.parseInt(this.interfaces.get(748).getComponent(8).getText()) <= EatingPoint + this.skills.getRealLevel(3)))
      {
        RSItem localRSItem2 = this.inventory.getItem(this.FoodIDS);
        if (localRSItem2 != null) {
          sleep(random(1000, 1300));
          if (localRSItem2.doAction("eat")) {
            waitForAnim(1000);
            sleep(random(200, 400));
          }
        }
      }
      this.CrackState = 0;
      return true;
    }
    return false;
  }

  private void Quit()
  {
    if (this.TakeAShot == true) {
      this.env.saveScreenshot(true);
      sleep(500);
    }
    stopScript();
  }

  private boolean directWalk(RSTile paramRSTile)
  {
    int i = random(3, 5);
    int j = paramRSTile.getX(); int k = paramRSTile.getY();
    int m = getMyPlayer().getLocation().getX(); int n = getMyPlayer().getLocation().getY();

    int i1 = j - m; int i2 = k - n;
    double d1 = Math.sqrt(Math.pow(j - m, 2.0D) + Math.pow(i2, 2.0D));

    double d2 = random(12, 17) / d1;
    int i3 = (int)(m + d2 * i1); int i4 = (int)(n + d2 * i2);
    RSTile localRSTile = new RSTile(i3, i4);
    if ((localRSTile.getX() <= 0) || (localRSTile.getY() <= 0))
    {
      log("directWalk() failed, error with the tile.");
      return false;
    }
    if (d1 < 10.0D) {
      localRSTile = paramRSTile;
    }
    if (!this.walking.walkTileMM(localRSTile, 1, 1)) {
      log("Didn't even click the map.");
      return false;
    }
    long l = System.currentTimeMillis();

    while ((System.currentTimeMillis() - l < random(800, 1200)) && 
      (!getMyPlayer().isMoving()))
    {
      sleep(50);
    }
    if (!getMyPlayer().isMoving()) {
      return false;
    }
    if (random(0, 25) == random(0, 25)) {
      this.walking.walkTileMM(localRSTile, 1, 1);
    }
    if (random(0, 10) == random(0, 10)) {
      this.mouse.moveRandomly(100);
    }
    if (random(0, 15) == random(0, 15)) {
      this.camera.setAngle(random(0, 360));
    }
    if (random(0, 15) == random(0, 15)) {
      this.game.openTab(random(0, 17));
      sleep(random(300, 1000));
      this.game.openTab(4);
    }

    while (System.currentTimeMillis() - l < random(3000, 4000)) {
      if (i >= 0) {
        if (this.walking.getDestination() != null)
        {
          try
          {
            if (this.calc.distanceTo(this.walking.getDestination()) <= i)
              return true;
          }
          catch (Exception localException1) {
            this.log.severe("Failed to get destination.");
          }
        }
        else return true;

      }
      else if (this.walking.getDestination() != null)
      {
        try
        {
          if (this.calc.tileOnScreen(this.walking.getDestination()))
            return true;
        }
        catch (Exception localException2) {
          this.log.severe("Failed to get destination.");
        }
      }
      else return true;

      sleep(100);
    }

    return false;
  }

  private void smallWalk() {
    RSTile localRSTile = nearestFreeSpot(false);
    if (localRSTile == null)
      return;
    if (this.calc.tileOnScreen(localRSTile)) {
      this.tiles.doAction(localRSTile, "Walk here");
      waitToMove(1000);
      this.mouse.moveSlightly();
      waitToStop(3000);
    } else {
      directWalk(localRSTile);
    }
  }

  private boolean atASafe()
  {
    return (inRectangle(3055, 4970, 3055, 4970)) || (inRectangle(3057, 4970, 3057, 4970)) || (inRectangle(3055, 4977, 3055, 4977)) || (inRectangle(3057, 4977, 3057, 4977));
  }

  private FallenSafeCracker.State getState()
  {
    RSNPC localRSNPC = this.npcs.getNearest(new int[] { 2271 });
    if ((!this.inventory.containsOneOf(this.FoodIDS)) || ((!this.inventory.contains(5560)) && (this.UseStethoscope == true)) || (this.inventory.isFull()))
    {
      if ((localRSNPC != null) && (localRSNPC.isOnScreen())) {
        if (this.bank.isOpen()) {
          return FallenSafeCracker.State.BANK;
        }
        return FallenSafeCracker.State.OPENBANK;
      }

      return FallenSafeCracker.State.WALKTOBANK;
    }

    if ((this.North) || (this.South)) {
      if (atASafe()) {
        return FallenSafeCracker.State.CRACK;
      }
      return FallenSafeCracker.State.SMALLWALK;
    }

    return FallenSafeCracker.State.WALKTOSAFES;
  }

  public void messageReceived(MessageEvent paramMessageEvent)
  {
    if (paramMessageEvent.getMessage().contains("cracking")) {
      this.CrackState = 1;
    } else if (paramMessageEvent.getMessage().contains("trigger")) {
      this.CrackState = 2;
      this.Trapped += 1;
    } else if (paramMessageEvent.getMessage().contains("Nothing")) {
      this.CrackState = 2;
    } else if (paramMessageEvent.getMessage().contains("eat")) {
      this.CrackState = 0;
    } else if (paramMessageEvent.getMessage().contains("loot")) {
      this.CrackState = 3;
      this.Cracked += 1;
    } else if (paramMessageEvent.getMessage().contains("level 50")) {
      log("Level 50 Thieving is required to be able to use this script.");
      Quit();
    }
  }

  private boolean IsChangeRequired() {
    if (this.change) {
      if ((someoneBeneathMe()) && ((this.SouthLeft) || (this.SouthRight) || (this.NorthRight) || (this.NorthLeft)))
      {
        if (this.advSwitch) {
          if (this.defined) {
            if (!this.switchTimer.isRunning())
            {
              this.defined = false;
              this.switching = true;
              log("Loc-Switch initiated.");
              this.waitingForMovement = false;
              return true;
            }
            this.waitingForMovement = true;
            this.switching = false;
            return false;
          }

          this.switchTimer = new Timer(random(1000, 3000) * 60);
          this.defined = true;
          return false;
        }

        this.switching = true;
        log("Loc-Switch initiated.");
        this.waitingForMovement = false;
        return true;
      }

      this.waitingForMovement = false;
      this.switching = false;
      if (this.switchTimer.isRunning()) {
        if (this.browseCounter > 9) {
          this.switchTimer.setEndIn(5L);
          this.browseCounter = 0;
          return false;
        }
        this.browseCounter += 1;
        return false;
      }

      this.browseCounter = 0;
      return false;
    }

    return false;
  }

  private boolean SwitchPosition()
  {
    if ((!this.NW.free) && (!this.NE.free) && (!this.SW.free) && (!this.SE.free)) {
      log("All spots were taken.. Logging out. :/");
      Quit();
      return false;
    }
    long l = System.currentTimeMillis();
    RSTile localRSTile = nearestFreeSpot(true);

    while ((System.currentTimeMillis() - l < random(15000, 20000)) && (!getMyPlayer().getLocation().equals(localRSTile))) {
      if (!getMyPlayer().getLocation().equals(localRSTile)) {
        if (this.calc.tileOnScreen(localRSTile)) {
          this.walking.walkTileOnScreen(localRSTile);
          waitToGetClose(0, random(2000, 3000)); continue;
        }
        this.walking.walkTileMM(localRSTile);
        waitToGetClose(3, random(5000, 6000));
      }
    }

    if (getMyPlayer().getLocation().equals(localRSTile)) {
      log("Location-Switch completed.");
      return true;
    }
    log("Location-Switch failed.");
    return false;
  }

  public int loop()
  {
    this.mouse.setSpeed(random(5, 8));
    if (failSafes())
      return 500;
    scanner();
    if (IsChangeRequired()) {
      SwitchPosition();
      return 300;
    }
    Object localObject;
    switch (FallenSafeCracker.1.$SwitchMap$FallenSafeCracker$State[getState().ordinal()]) {
    case 1:
      if (this.inventory.isItemSelected()) {
        this.inventory.clickSelectedItem(true);
      }
      if (this.camera.getPitch() < 80) {
        this.up = true;
        new FallenSafeCracker.CameraHeightThread(this).start();
      }
      if (!this.randomized) {
        int i = random(0, 100);
        if (i >= 49) {
          this.dest = new RSTile(3056, 4978);
        }
        if (i <= 48) {
          this.dest = new RSTile(3056, 4969);
        }
        this.randomized = true;
      }
      directWalk(this.dest);
      this.CrackState = 0;
      break;
    case 2:
      if (this.inventory.isItemSelected()) {
        this.inventory.clickSelectedItem(true);
      }
      if (this.camera.getPitch() < 80) {
        this.up = true;
        new FallenSafeCracker.CameraHeightThread(this).start();
      }
      smallWalk();
      this.CrackState = 0;
      break;
    case 3:
      this.randomized = false;
      if (this.CrackState == 0) {
        getInvCounts();
        crackSafe();
        this.CrackState = 1;
      } else if (this.CrackState == 1) {
        waitForStateChange(random(6500, 7500));
        if (this.CrackState != 1) break;
        this.CrackState = 2;
      }
      else if (this.CrackState == 2) {
        sleep(random(300, 400));
        getInvCounts();
        if (!this.clickFirst) {
          sleep(random(100, 200));
        }
        crackSafe();
      } else {
        sleep(random(200, 300));
        getInvCounts();
        waitForSafe(random(1000, 2000));
        crackSafe();
      }
      break;
    case 4:
      if (this.inventory.isItemSelected()) {
        this.inventory.clickSelectedItem(true);
      }
      if ((this.inventory.isFull()) && 
        (this.inventory.containsOneOf(this.FoodIDS)) && 
        (Integer.parseInt(this.interfaces.get(748).getComponent(8).getText()) <= this.skills.getRealLevel(3) * 10 - 100))
      {
        this.inventory.getItem(this.FoodIDS).doAction("eat");
        waitForAnim(1000);
        sleep(random(200, 400));
      }
      else
      {
        if (this.camera.getPitch() < 80) {
          this.up = true;
          new FallenSafeCracker.CameraHeightThread(this).start();
        }
        RSNPC localRSNPC = this.npcs.getNearest(new int[] { 2271 });
        CameraAntiBan();
        if (localRSNPC != null) {
          localObject = this.npcs.getNearest(new int[] { 2271 }).getLocation();
          if (localRSNPC.isOnScreen()) break;
          directWalk((RSTile)localObject);
        }
        else
        {
          directWalk(this.approxBank);
        }
      }break;
    case 5:
      localObject = this.npcs.getNearest(new int[] { 2271 });
      if ((!((RSNPC)localObject).doAction("Bank")) || 
        (!waitForIF(this.interfaces.get(762), 2000))) break;
      sleep(random(200, 300)); break;
    case 6:
      if (!this.bank.isOpen())
        break;
      if (this.UseStethoscope) {
        if (this.inventory.getCountExcept(new int[] { 5560, this.FoodID }) > 0) {
          try {
            this.bank.depositAll();
            waitForDepositedItem(random(2000, 3000));
          } catch (Exception localException1) {
          }
          CameraAntiBan();
          break;
        }
      }
      if (!this.UseStethoscope) {
        if (this.inventory.getCountExcept(new int[] { this.FoodID }) > 0) {
          try {
            this.bank.depositAll();
            waitForDepositedItem(random(2000, 3000));
          } catch (Exception localException2) {
          }
          CameraAntiBan();
          break;
        }
      }
      if ((this.UseStethoscope) && (!this.inventory.contains(5560))) {
        if (!WD(5560, 1)) break;
        CameraAntiBan();
        waitForWithdrawnItem(5560, random(2000, 3000));
      }
      else
      {
        if (!WD(this.FoodID, FoodWDAmount)) break;
        CameraAntiBan();
        waitForWithdrawnItem(this.FoodID, random(2000, 3000));
      }
    }

    timeToQuit();
    return random(10, 50);
  }

  public void hoverObject()
  {
    examineRandomObject(5);
    sleep(randGenerator(50, 1000));
    int i = randGenerator(0, 4);
    sleep(randGenerator(100, 800));
    if ((i == 1) && (i == 2))
      this.mouse.move(1, 1, 760, 500);
  }

  int randGenerator(int paramInt1, int paramInt2)
  {
    return paramInt1 + (int)(Math.random() * (paramInt2 - paramInt1));
  }

  public RSTile examineRandomObject(int paramInt) {
    RSTile localRSTile1 = getMyPlayer().getLocation();
    ArrayList localArrayList = new ArrayList();
    for (int i = 1; i < paramInt * paramInt; i += 2) {
      for (int j = 0; j < i; j++) {
        for (int k = 0; k < i; k++) {
          int m = (i + 1) / 2 - 1;
          if ((j > 0) && (j < i - 1)) {
            k = i - 1;
          }
          RSTile localRSTile3 = new RSTile(localRSTile1.getX() - m + j, localRSTile1.getY() - m + k);

          RSObject localRSObject = this.objects.getTopAt(localRSTile3);
          if ((localRSObject == null) || (!this.calc.tileOnScreen(localRSObject.getLocation())))
            continue;
          localArrayList.add(localRSObject.getLocation());
        }
      }
    }

    if (localArrayList.size() == 0) {
      return null;
    }
    if ((localArrayList.size() > 0) && (localArrayList != null)) {
      RSTile localRSTile2 = (RSTile)localArrayList.get(randGenerator(0, localArrayList.size()));

      Point localPoint = this.calc.tileToScreen(localRSTile2);
      if (localPoint != null)
        try {
          this.mouse.move(localPoint);
          if (this.menu.doAction("xamine"));
          sleep(random(100, 500));
        }
        catch (NullPointerException localNullPointerException) {
        }
    }
    return null;
  }

  public void antiBan() {
    try {
      int i = random(1, 2500);
      int j = random(1, 133);
      int k = random(1, 33);
      int m = random(1, 833);
      int n;
      if (k == 5) {
        n = random(1, 10);
        switch (n) {
        case 1:
          this.mouse.move(200, 300, 100, 100);
          sleep(random(100, 500));
          break;
        case 2:
          this.mouse.move(100, 700, 1000, 1000);
          break;
        case 3:
          this.mouse.move(340, 200, 300, 200);
          sleep(random(100, 500));
          break;
        case 4:
          this.mouse.move(122, 458, 50, 10);
          sleep(random(100, 500));
          this.mouse.moveSlightly();
          break;
        case 5:
          this.mouse.move(340, 200, 300, 200);
          sleep(random(100, 500));
          break;
        case 6:
          this.game.openTab(random(0, 17));
          sleep(random(300, 1000));
          this.game.openTab(4);
          break;
        case 7:
          this.mouse.move(80, 70, 320, 170);
          sleep(random(100, 500));
          break;
        case 8:
          this.mouse.move(80, 70, 320, 170);
          sleep(random(100, 500));
          break;
        case 9:
          this.mouse.move(80, 70, 320, 170);
          sleep(random(100, 500));
        }
      }
      else if (j == 5) {
        n = random(1, 6);
        switch (n) {
        case 1:
          new FallenSafeCracker.CameraRotateThread(this).start();
          break;
        case 2:
          new FallenSafeCracker.CameraHeightThread(this).start();
          break;
        case 3:
          new FallenSafeCracker.CameraRotateThread(this).start();
          if (random(0, 100) <= random(0, 50)) break;
          sleep(random(100, 2000));
          new FallenSafeCracker.CameraRotateThread(this).start(); break;
        case 4:
          new FallenSafeCracker.CameraHeightThread(this).start();
          if (random(0, 100) <= random(0, 50)) break;
          sleep(random(100, 2000));
          new FallenSafeCracker.CameraHeightThread(this).start(); break;
        case 5:
          new FallenSafeCracker.CameraRotateThread(this).start();
          new FallenSafeCracker.CameraHeightThread(this).start();
          if (random(0, 100) <= random(0, 50)) break;
          sleep(random(100, 2000));
          new FallenSafeCracker.CameraRotateThread(this).start();
          if (random(0, 100) <= random(0, 50)) break;
          sleep(random(100, 1000));
          new FallenSafeCracker.CameraHeightThread(this).start();
        }

      }
      else if (i == 5) {
        this.game.openTab(2);
        sleep(random(400, 800));
        this.mouse.move(554, 213, 175, 215);
        sleep(random(400, 800));
        this.mouse.move(554, 213, 175, 215);
        sleep(random(400, 1000));
        this.mouse.moveRandomly(700);
        sleep(random(300, 500));
        this.game.openTab(4);
      } else if (m == 5) {
        hoverObject();
        sleep(random(400, 800));
        this.mouse.moveRandomly(750);
        sleep(random(400, 800));
      }
    }
    catch (Exception localException)
    {
    }
  }

  public void onFinish()
  {
    log(this.XPGained + " Thieving Exp Gained  ||  " + this.GainedProfit + " Profit made in: " + this.hours + ":" + this.minutes + ":" + this.seconds + "!");

    log("Thank you for using Fallen's Safe Cracker.");
  }

  public void mouseClicked(MouseEvent paramMouseEvent)
  {
  }

  public void mouseEntered(MouseEvent paramMouseEvent)
  {
  }

  public void mouseExited(MouseEvent paramMouseEvent)
  {
  }

  public void mousePressed(MouseEvent paramMouseEvent)
  {
    Point localPoint = new Point(paramMouseEvent.getPoint());
    Rectangle localRectangle1 = new Rectangle(416, 458, 32, 15);
    Rectangle localRectangle2 = new Rectangle(448, 458, 32, 15);
    Rectangle localRectangle3 = new Rectangle(480, 458, 32, 15);

    if ((localRectangle1.contains(localPoint)) && (this.renew == true)) {
      if (this.paint == true) {
        this.paint = false;
        this.renew = false;
      } else {
        this.paint = true;
        this.renew = false;
      }
    }
    if ((localRectangle2.contains(localPoint)) && (this.renew == true)) {
      if (this.RT == true) {
        this.RT = false;
        this.renew = false;
      } else {
        this.RT = true;
        this.renew = false;
      }
    }
    if ((localRectangle3.contains(localPoint)) && (this.renew == true))
      if (this.extra == true) {
        this.extra = false;
        this.renew = false;
      } else {
        this.extra = true;
        this.renew = false;
      }
  }

  public void mouseReleased(MouseEvent paramMouseEvent)
  {
    this.renew = true;
  }

  public void mouseDragged(MouseEvent paramMouseEvent)
  {
  }

  public void mouseMoved(MouseEvent paramMouseEvent)
  {
  }
}